<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<h1 style=text-align:center>录入数据成功</h1>
<%
request.setCharacterEncoding("utf-8");
Connection con;
//驱动程序名
String driver = "com.mysql.jdbc.Driver";
//URL指向要访问的数据库名mydata
String url = "jdbc:mysql://localhost:3306/qimo";
//MySQL配置时的用户名
String user = "root";
//MySQL配置时的密码
String password = "ideacmblog";
String mingzi=null;
String mima=null;
String youxiang=null;
String dianhua=null;
try {
    //加载驱动程序
    Class.forName(driver);
    //1.getConnection()方法，连接MySQL数据库！！
    con = DriverManager.getConnection(url,user,password);
    if(!con.isClosed())
        System.out.println("Succeeded connecting to the Database!");
    //2.创建statement类对象，用来执行SQL语句！！
    Statement statement = con.createStatement();
    //要执行的SQL语句
    String n=request.getParameter("logname");
    String d=request.getParameter("password");
    String c=request.getParameter("email");
    String s=request.getParameter("phone");
    String sql = "insert into ljx (mingzi,mima,youxiang,dianhua)values('"+n+"','"+d+"','"+c+"','"+s+"')";
    statement.executeUpdate(sql);
    sql = "select * from ljx";
    //3.ResultSet类，用来存放获取的结果集！！
    ResultSet rs = statement.executeQuery(sql);     
    while(rs.next()){
     String na=rs.getString("mingzi"); 
     String de=rs.getString("mima");
     String cl=rs.getString("youxiang");
     String se=rs.getString("dianhua");
     mingzi=na;
     mima=de;
     youxiang=cl;
     dianhua=se;
    }
    rs.close();
    con.close();
    }
    catch(ClassNotFoundException e) {   
    //数据库驱动类异常处理
    System.out.println("Sorry,can`t find the Driver!");   
    e.printStackTrace();   
    } catch(SQLException e) {
    //数据库连接失败异常处理
    e.printStackTrace();  
    }catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
}finally{
    System.out.println("数据库数据成功获取！！");
}	
%>
<html>
<body background="picture/299984.jpg">
<head>
<table border=1>
<tr><td>姓名</td><td><%=mingzi %></td></tr>
<tr><td>密码</td><td><%=mima %></td></tr>
<tr><td>邮箱</td><td><%=youxiang %></td></tr>
<tr><td>电话</td><td><%=dianhua %></td></tr>
</head>
</table>
</body>
</html>


